#include <iostream>
using namespace std;
template <typename T>
class Node {
public:
	template <typename T>
	friend class linkList;
	Node();
	Node(T value, Node<T>* next);
	~Node();
private:
	T value;
	Node<T>* next;
};
template <typename T>
Node<T>::Node(){
	value = 10000;
	next = nullptr;
}
template <typename T>
Node<T>::Node(T value, Node<T>* next) {
	this->value = value;
	this->next = next;
}
template <typename T>
Node<T>::~Node() {

}
template <typename T>
class arrayList{
public:
	arrayList(int n);
	~arrayList();
	void Josephus(int n, int m);
private:
	T* element;
};
template <typename T>
arrayList<T>::arrayList(int n) {
	element = new T[n+1];
}
template <typename T>
arrayList<T>::~arrayList() {
	delete element;
}
template <typename T>
void arrayList<T>::Josephus(int n, int m) {
	int count = 0;
	int deathcount = 0;
	for (int i = 0; i <= n; i++) {
		element[i] = i;
	}
	
	while (deathcount < n) {
		for (int j = 1; j <= n; j++) {
			if (element[j] != 0)
				count++;
			else if(element[j] == 0)
				continue;
			if (count%m == 0){
				deathcount++;
				if (deathcount == n)
					cout << element[j]<<"/"<<'\n';
				else
					cout << element[j] << " ";
				element[j] = 0;
			}
		}
	}
	return;
}
template <typename T>
class linkList {
public:
	linkList();
	linkList(Node<T>* firstNode);
	~linkList();
	void insertGroups(const int n);
	bool deletebyIndex(int index);
	void Josephus(int n,int m);

private:
	Node<T>* firstNode;
};
template <typename T>
linkList<T>::linkList() {
	firstNode = new Node<T>;
}
template <typename T>
linkList<T>::linkList(Node<T>* firstNode) {
	this->firstNode = firstNode;
}
template <typename T>
linkList<T>::~linkList() {
	Node<T>* currentNode = firstNode;
	while (currentNode->next != firstNode) 
		currentNode = currentNode->next;
	currentNode->next = nullptr;
	while (firstNode != nullptr) {
		currentNode = firstNode->next;
		delete firstNode;
		firstNode = currentNode;
	}
}
template <typename T>
void linkList<T>::insertGroups(const int n) {
	int count = 1;
	Node<T>* lastNode = firstNode;
	while (count <= n) {
		lastNode->next = new Node<T>(count, nullptr);
		lastNode = lastNode->next;
		count++;
	}
	lastNode->next = firstNode;
}
template <typename T>
bool linkList<T>::deletebyIndex(int index) {
	if (firstNode->next == nullptr)
		return false;
	Node<T>* currentNode = firstNode->next;
	while (currentNode != firstNode) {
		if (currentNode->value == index) {
			Node<T>* preNode = firstNode;
			while (preNode->next != currentNode)
				preNode = preNode->next;
			preNode->next = currentNode->next;
			delete currentNode;
			return true;
		}
		currentNode = currentNode->next;
	}
	return false;
}
template <typename T>
void linkList<T>::Josephus(int n,int m) {
	int count = 1;
	Node<T>* currentNode = firstNode->next;
	while (firstNode->next->next != firstNode) {
		if(count %m == 0){
			Node<T>* preNode = firstNode;
			while (preNode->next != currentNode) 
				preNode = preNode->next;
			preNode->next = currentNode->next;
			Node<T>* deletedNode = currentNode;
			currentNode = currentNode->next;
			cout << deletedNode->value << " ";
 				delete deletedNode;
				
			if (currentNode == firstNode) 
				currentNode = currentNode->next;
			count++;
			continue;
		}
		currentNode = currentNode->next;
		if (currentNode == firstNode)
			currentNode = currentNode->next;
		count++;
	}
	cout << firstNode->next->value<<"/"<<'\n';
	return;
}